import {messages} from "share/common";
import React, {Component} from 'react';
import { connect } from "react-redux";
import {Radio} from "antd";
import SlideFrameContent from "../../../slide-frame-content";
import claimAmountService from "../../claim-amount.service";

const RadioGroup = Radio.Group;

@connect(mapStateToProps)
class ClaimAmountVerificationBasicDetail extends Component {

  record = this.props.params.record;

  priorityInfo = {
    top: 'TENANT',
    disabled: true,
    value: {
      levelCode: 'TENANT',
      levelOrgId: this.props.tenant.id,
      levelOrgName: this.props.tenant.tenantName,
      distribution: {
        companies: this.record.companies
      }
    }
  };

  options1 = [
    {label: messages('expense-8.key163')/*可修改*/, value: true},
    {label: messages('expense-8.key166')/*不可修改*/, value: false}
  ];

  options2 = [
    {label: messages('expense-8.key386')/*按最大值核定*/, value: "MAX_VALUE"},
    {label: messages('expense-8.key387')/*按最小值核定*/, value: "MIN_VALUE"},
    {label: messages('expense-8.key388')/*累计核定*/, value: "ACCUM_VALUE"}
  ];

  formList = [{
    id: 'amountEditable',
    label: messages('expense-8.key389')/*员工可修改金额*/,
    extra: messages('expense-8.key390')/*【可修改金额】员工可修改核定金额，核定金额需小于等于费用原金额*/,
    initialValue: this.record.id ? this.record.amountEditable : false,
    component: <RadioGroup disabled={this.record.readOnly} options={this.options1}/>
  }, {
    id: 'multiRulesCalcMode',
    label: messages('expense-8.key391')/*费用命中多条规则*/,
    extra: messages('expense-8.key392')/*【累计核定】例如配置了替票扣减10%，费用超期扣减20%，替票且超期则扣减30%*/,
    initialValue: this.record.id ? this.record.multiRulesCalcMode : "ACCUM_VALUE",
    component: <RadioGroup disabled={this.record.readOnly} options={this.options2}/>
  }];

  dealParams = values => {
    values.id = this.record.id;
    return values;
  };

  render() {
    const { record, disabled } = this.props.params;
    return (
      <SlideFrameContent
        disabled={record.readOnly || disabled}
        enabled={record.id ? record.enabled : true}
        priorityInfo={this.priorityInfo}
        formInfo={[{
          title: messages('expense-8.key352')/*详细设置*/,
          list: this.formList
        }]}
        onlyCompaniesId={false}
        service={claimAmountService.saveBaseRule}
        dealParams={this.dealParams}
        close={this.props.close}
      />
    );
  }
}

function mapStateToProps(state) {
  return {
    tenant: state.login.tenant
  }
}

export default ClaimAmountVerificationBasicDetail;
